package leetcode.editor.cn.util.list.singly;

public class ListUtil {

    private static ListUtil util = new ListUtil();

    private ListUtil() {
    }

    public static ListUtil getInstance() {
        return util;
    }

    public ListNode generateFromArray(int... arr) {
        if (arr == null || arr.length == 0) return null;
        ListNode head = new ListNode(arr[0]);

        ListNode node = head;

        for (int i = 1; i < arr.length; i++) {
            node.next = new ListNode(arr[i]);
            node = (ListNode) node.next;
        }

        return head;
    }
}
